package com.sonny.jdom;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.jdom.DocType;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

public class JdomTestListElements {

	/**
	 * @param args
	 */
	static String xmlTestFile1 = "toll_report.xml";


	public static void main(String[] args) throws IOException, JDOMException {

        //if( args.length != 1 ) showUsage();

        SAXBuilder builder = new SAXBuilder();
        try{
        	
            Document doc = builder.build(xmlTestFile1);
            DocType docType = doc.getDocType();
            
            Element root = doc.getRootElement();
            trace("Input File : " + xmlTestFile1);
            if( docType == null ) {
                trace("DocType is null !!");
            }else {
                trace("getElementName() : " + docType.getElementName());
                trace("getPublicID() : " + docType.getPublicID() );
                trace("getSystemID() : " + docType.getSystemID() );
                trace(docType.toString());

                trace("==============================================");
                trace("root.getName() : " + root.getName());
                
                List children = root.getChildren();
                Iterator iter = children.iterator();
                while( iter.hasNext() ) {
                    Object obj = iter.next();
                    trace(obj.toString());
                    trace("[Class Name] " + obj.getClass().getName());
                }
            }
        }catch(Exception e) {
            e.printStackTrace();
        }
		
		System.out.println("Completed");

	}
	
    public static void showUsage() {
        System.out.println("Usage : run DOMBuilderExample ");
        System.exit(1);
    }
    public static void trace(String data) {
        System.out.println("[ DOMBuilderExample ] " + data);
    }

}
